package com.fastloan.mgt.application.phoneapprove.controller;

import com.fastloan.common.model.CheckResult;
import com.fastloan.mgt.application.phoneapprove.model.ApplicationPhoneApprove;
import com.fastloan.mgt.application.phoneapprove.service.ApplicationPhoneApproveService;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yanwe
 * createTime 2017-11-2017/11/10 17:55
 */
@RestController
@RequestMapping("/api/application/phoneApprove")
public class ApplicationPhoneApproveController extends BaseController<ApplicationPhoneApprove> {

    @Autowired
    private ApplicationPhoneApproveService applicationPhoneApproveService;

    @PostMapping("/approve")
    public ResultTo approve(ApplicationPhoneApprove applicationPhoneApprove
            , @RequestPart(value = "approveFiles",required = false) MultipartFile[] approveFiles) {
        CheckResult checkResult = applicationPhoneApproveService.approve(applicationPhoneApprove, approveFiles);
        return checkResult.isCheckResult() ? new ResultTo() :
                new ResultTo(ResultEnum.OPERATION_FAILED,checkResult.getCheckMsg());
    }

    @GetMapping("/{applicationId}")
    public ResultTo getApprove(@PathVariable("applicationId") String applicationId) {
        ApplicationPhoneApprove approveInfo = applicationPhoneApproveService.getApproveInfo(applicationId);
        return new ResultTo().setData(approveInfo);
    }

    @PostMapping("/history")
    public ResultTo approveHistory() {
        Map<String, Object> map = new HashMap<>();
        map.put("approveUser", ManagerKit.getUserId());
        return dataPage("selectApplicationPhoneApproveVo",map);
    }
}
